Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Kerne32Util method to facilitate checking that calls to LocalFree/GlobalFree are successful #606

Merged

Conversation

lgoldstein
Copy link
Contributor

The current code calls Local/GlobalFree without checking that they succeeded.

@lgoldstein lgoldstein force-pushed the validate-local-free branch 3 times, most recently from 4e0f939 to abdd1f9 Compare March 3, 2016 07:52
@@ -38,6 +38,7 @@ Features
* [#589](https://github.com/java-native-access/jna/pull/589): Use MethodResultContext in direct mapping (as done in interface mapping) - [@marco2357](https://github.com/marco2357).
* [#595](https://github.com/java-native-access/jna/pull/595): Allow calling COM methods/getters requiring hybrid calling (METHOD+PROPERTYGET) - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#582](https://github.com/java-native-access/jna/pull/582): Mavenize the build process - Phase 1: building the native code via Maven [@lgoldstein](https://github.com/lgoldstein)
* [#606](https://github.com/java-native-access/jna/pull/606): Added Kerne32Util method to facilitate checking that calls to LocalFree/GlobalFree are successful [@lgoldstein](https://github.com/lgoldstein)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax of these is - [@name](link)., mind fixing this one and the one above too please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dblock
Copy link
Member

dblock commented Mar 3, 2016

I think that in the Util class we only want the version that raises an exception, just for consistency with everything else. Cause if you want to check the error yourself you can call the Kernel32 original API, right? I would also just call these localFree and such?

@lgoldstein
Copy link
Contributor Author

Normally, I would agree with you - but as you can see from my code changes, most people don't bother to check the return value or the error. By using this piece of code ourselves we give a good example as to the kind of coding standards we recommend. Furthermore, by providing these helper methods we make acceptance and usage of said standards more likely.

Also, specifically for the version with the return code - 2 reasons to keep it (IMO):

  1. Unit tests (as shown) - provide more information if free failed (the error code in this case)
  2. Perhaps someone wants to handle the error themselves somehow and not necessarily throw an exception - let's not second guess the needs of the users.

@lgoldstein
Copy link
Contributor Author

@dblock Please let me know if you approve of the request in view of the clarifications since I am waiting on it in order to add a critical fix for issue #604.

lgoldstein added a commit that referenced this pull request Mar 5, 2016
Added Kerne32Util method to facilitate checking that calls to LocalFree/GlobalFree are successful
@lgoldstein lgoldstein merged commit 228177e into java-native-access:master Mar 5, 2016
@lgoldstein lgoldstein deleted the validate-local-free branch March 5, 2016 09:02
@dblock
Copy link
Member

dblock commented Mar 6, 2016

Personally I still don't love having both freeLocalMemory and validateFreeLocalMemory, turning an error into an exception is great, but turning an error into another kind of error (via getLastError) is not. The Util classes are all throwing exceptions and never return error codes, this breaks that principle and opens the door for all kinds of wild behavior in the library.

@twall
Copy link
Contributor

twall commented Mar 6, 2016

I agree on this one, if someone wants an error code they can call GetLastError on their own. Just make freeLocalMemory() raise an exception and get rid of the “validateXXX” variants.

On Mar 6, 2016, at 8:46 AM, Daniel Doubrovkine (dB.) @dblockdotorg [email protected] wrote:

Personally I still don't love having both freeLocalMemory and validateFreeLocalMemory, turning an error into an exception is great, but turning an error into another kind of error (via getLastError) is not. The Util classes are all throwing exceptions and never return error codes, this breaks that principle and opens the door for all kinds of wild behavior in the library.


Reply to this email directly or view it on GitHub.

@lgoldstein
Copy link
Contributor Author

but turning an error into another kind of error (via getLastError) is not

The code does not turn one error into another - it simply gives the programmer the choice to examine the returned error code and decide on another kind of handling rather than throwing an exception.

Just make freeLocalMemory() raise an exception and get rid of the “validateXXX” variants

If you feel this strongly about this I will do it (as a separate PR).

@dblock
Copy link
Member

dblock commented Mar 6, 2016

@lgoldstein Yes, you're right, it gives the programmer the choice to examine the returned error code. I fairly strongly feel that the programmer should not have that choice in a Util class as a matter of consistency.

@lgoldstein
Copy link
Contributor Author

Very well then, I will publish a PR that adheres to this convention soon (unless you'd rather I do it directly on the master branch)

mstyura pushed a commit to mstyura/jna that referenced this pull request Sep 9, 2024
Motivation:

we are a bit behind of the current quiche HEAD.

Modifications:

Update to latest HEAD

Result:

Use latest quiche code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants